<?php
require_once 'config.php';
require_once 'common.php';
require_once 'ResultData.php';

$result = new ResultData();

$id = trim($_REQUEST['id']);
$name = trim($_REQUEST['name']);
$psd = trim($_REQUEST['password']);

if ($id == "") {
    $result->code = 404;
    $result->msg = "id未填写";
    exit(json_encode($result));
}

if ($name == "") {
    $result->code = 404;
    $result->msg = "name未填写";
    exit(json_encode($result));
}

if ($psd == "") {
    $result->code = 404;
    $result->msg = "password未填写";
    exit(json_encode($result));
}

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "UPDATE t_login SET name = '{$name}', password = '{$psd}' WHERE id = {$id}";

$con->query($sql);

mysqli_close($con);

exit(json_encode($result));
